﻿using System;
using System.Web.UI.WebControls;
using Utilities;
using SocialShare.BusinessLogicLayer;
using SocialShare.BusinessEntities;
using SocialShare.DAL.Facades;

public partial class Admin_approve_posts : System.Web.UI.Page
{

    private Int32 PostId
    {
        get
        {
            try
            {
                if (!string.IsNullOrEmpty(Request.QueryString["postId"].ToString()))
                {
                    return Convert.ToInt32(Request.QueryString["postId"].ToString());
                }
                else
                {
                    return -1;
                }
            }
            catch
            {
                return -1;
            }
        }
    }



    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            LoadData();
        }
    }

    private void LoadData()
    {
        ForumFacade bll = new ForumFacade();
        repViewPosts.DataSource=bll.GetAllForumMessagesByID(PostId);
        repViewPosts.DataBind();
    }
    protected void repViewPosts_ItemCommand(object source, RepeaterCommandEventArgs e)
    {
        Int32 postId = Convert.ToInt32(e.CommandArgument.ToString());
        ForumFacade bll = new ForumFacade();
        if (e.CommandName == "UNPUBLISH")            
        {
            SocailShare_Forum_Messages post = bll.GetForumMessagesByPostId(postId);
            post.Status = (Int32)ForumStatus.UnPublished;
            bll.UpdateForumMessages(post);
            LoadData();
        }
        else if (e.CommandName == "PUBLISH")
        {
            SocailShare_Forum_Messages post = bll.GetForumMessagesByPostId(postId);
            post.Status = (Int32)ForumStatus.Published;
            bll.UpdateForumMessages(post);
            LoadData();
        }
        else if (e.CommandName == "DELETE")
        {
            SocailShare_Forum_Messages post = bll.GetForumMessagesByPostId(postId);
            post.Status = (Int32)ForumStatus.Deleted;
            bll.UpdateForumMessages(post);
            LoadData();
        }
        else
        {
            // Do Nothing
        }

    }
}